<template>
	<view class="content_view">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'设备列表'"></u-navbar>
		<view class="">
				<u-checkbox-group @change="checkboxGroupChange" width="80%">
					<u-checkbox 
						v-model="item.checked" 
						v-for="(item, index) in euqipmentList" :key="index" 
						:name="item.ucId" 
					>{{item.name}}</u-checkbox>
				</u-checkbox-group>
				<u-button @click="batchSign()">批量标识</u-button>
		</view>
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText"  />
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				euqipmentList:[],
				euqipmentUcIds: [],
				pageNum:0,
				ucId:'',
				enterpriseId:'',
				finished:false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多数据了'
				},
				scrollTop:0
			}
		},
		onLoad(e) {
			this.ucId=e.ucId
			this.enterpriseId=e.enterpriseId
		},
		onShow() {
			this.getInMaintenanceInfoPage()
		},
		methods: {
			checkedAll() {
						this.euqipmentList.map(val => {
							// val.checked = true;
						})
					},
			getInMaintenanceInfoPage(){
				this.pageNum++
				let _this = this
				return new Promise((resolve, reject) => {
					_this.utils.request("/api/app/equipment/getEquipmentPage", {enterpriseId:this.enterpriseId,pageNum:this.pageNum,pageSize:20}, "post", "app", true).then(res => {
						_this.euqipmentList.push(...res.data.list)
						_this.finished = (res.data.pageNum >= res.data.pages);
						if(_this.finished){
							_this.status = 'nomore';
						}
						this.loading=false
						resolve(res)
					}).catch(error => {
						reject(error)
					})
				})
			},
			checkboxGroupChange(e) {
				this.euqipmentUcIds = e;
				console.log(e)
			},
			batchSign(){
				this.utils.request("/api/app/maintenanceRecord/batchSign", {ucId: this.ucId,equipmentUcIds:this.euqipmentUcIds}, "post", "app", true).then(res => {
					
					uni.redirectTo({
					    url: '/pages/index/workorder/task/list'
					});
					
				}).catch(error => {
					console.log(error)
				})
			},
			
			onReachBottom() {
				if (this.finished) return;
				this.status = 'loading';
				this.getInMaintenanceInfoPage().then(res => {
					if (this.finished) this.status = 'nomore';
					else this.status = 'loading';
				}).catch(error => {
					this.loading = false
					this.status = 'nomore';
				})
			}
		}
	}
</script>

<style>

</style>
